﻿Public Partial Class MergeBooking
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim lbPage As Label = CType(Master.FindControl("lbPage"), Label)
            lbPage.Text = "MERGE BOOKING"
        End If
    End Sub

    Private Sub mergeNowBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mergeNowBtn.Click
        Dim db As DB_Class = New DB_Class()

        Dim isSameShip As Boolean = False
        Dim parent As String = parentBooking.Text.Trim()
        Dim child As String = childBooking.Text.Trim()
        db.queryString = "select * from Booking where Booking_no='" & parent & "'"
        Dim dtParent As DataTable = db.getTable("parent")

        db.queryString = "select * from Booking where Booking_no='" & child & "'"
        Dim dtChild As DataTable = db.getTable("child")


        If (dtParent.Rows.Count > 0 And dtChild.Rows.Count > 0) Then
            Dim veh1 As String = dtParent.Rows(0)("Vehicle_no").ToString()
            Dim veh2 As String = dtChild.Rows(0)("Vehicle_no").ToString()
            If (veh1 = veh2) Then
                isSameShip = True
            Else
                isSameShip = False
            End If
        End If
        If (isSameShip) Then
            Dim upd As String = "update Booking set isChildBooking='YES',parentBookingRef='" + parentBooking.Text + "' where Booking_no='" + childBooking.Text + "'"
            'Label1.Text = upd
            db.queryString = upd

            If (db.insertUpdate() = "") Then
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ทำการ Merge Booking\n Parent Booking : " & parentBooking.Text & "\n Child Booking : " & childBooking.Text & " \nสำเร็จ');window.location='frm_Booking.aspx'", True)
            Else
                ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ไม่สามารถทำการ Merge Booking ได้');", True)
            End If
        Else
            ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", "alert('ไม่สามารถทำการ Merge Booking ได้เนื่องจากไม่ใช่เรือรำเดียวกัน');", True)
        End If

    End Sub
End Class